/**
 * 后台功能
 * */


(function () {
})();


//获取列表
function getList(){
    var formData = {
        start: pages.start, limit: pages.limit,
    };
    $.ajax({
        type: apis.drugOrderIndex.method,
        url: apis.drugOrderIndex.url,
        data: formData,
        success: function (res) {
            console.log(res);
            var h = '', i, tbody = $('tbody');
            if (res.code < 0) {
                //msgPop({msg: res.msg});
                h = '';
                h += '<tr class="text-c">';
                h += '<td colspan="10">没有记录</td>';
                h += '</tr>';
                tbody.html(h);
                return
            }
            tbody.html(getHtml(res.data));
            $('#pageTotal').html(res.total);
            pages.total = res.total;
            pageHtml(pages);
        },
        error: function () {
            console.log('错误了！');
        }
    });
}
//HTML
function getHtml(d){
    var h = '', i;
    for (i = 0; i < d.length; i ++) {
        h += '<tr class="text-c">';
        h += '<td>' + d[i].id + '</td>';
        h += '<td>' + d[i].title + '</td>';
        h += '<td>' + d[i].uname + '</td>';
        h += '<td>' + d[i].price + '</td>';
        h += '<td>' + d[i].num + '</td>';
        h += '<td>' + d[i].accepter + '</td>';
        h += '<td>' + d[i].acceptDoor + '</td>';
        h += '<td>' + d[i].pstime + '</td>';
        h += '<td>' + d[i].status_name + '</td>';
        h += '<td>' + d[i].addtime + '</td>';
        h += '<td class="f-14">';
        //if (d[i].status == 2) {
            h += '<a href="javascript:;" onclick="lay_send(' + d[i].id + ');">';
            h += '发货';
            h += '</a>';
        //}
        //if (d[i].status == 3) {
            h += ' &nbsp; ';
            h += '<a href="javascript:;" onclick="lay_finish(' + d[i].id + ');">';
            h += '完成';
            h += '</a>';
        //}
        //h += '<br>';
        //h += '<a href="javascript:;" onclick="lay_del(' + d[i].id + ');" style="color: red;">';
        //h += '删除';
        //h += '</a>';
        h += '</td>';
        h += '</tr>';
    }
    return h;
}


//发货
function lay_send(v){
    var msg = '确认要 <b style="color: red; font-size: 20px;">发货</b> 吗？';
    layer.confirm(msg,function(index){
        $.ajax({
            type: apis.drugOrderSend.method,
            url: apis.drugOrderSend.url,
            data: { id: v },
            success: function (res) {
                console.log(res);
                if (res.code < 0) {
                    layerMsgErr(res.msg); return
                }
                layerMsgOk('操作成功!');
                setTimeout(function(){
                    top.location.reload();
                }, 500);
            },
            error: function () {
                console.log('错误了！');
            }
        });
    });
}


//完成
function lay_finish(v){
    var msg = '确认要 <b style="color: red; font-size: 20px;">完成</b> 吗？';
    layer.confirm(msg,function(index){
        $.ajax({
            type: apis.drugOrderFinish.method,
            url: apis.drugOrderFinish.url,
            data: { id: v },
            success: function (res) {
                console.log(res);
                if (res.code < 0) {
                    layerMsgErr(res.msg); return
                }
                layerMsgOk('操作成功!');
                setTimeout(function(){
                    top.location.reload();
                }, 500);
            },
            error: function () {
                console.log('错误了！');
            }
        });
    });
}